/**
 * Created by Freeman on 2016/6/27.
 */
"use strict";

var esearch = require('../../esearch/elasticsearch');

//搜索博客
exports.search = function (req,res,next) {
    var q = req.query.q;
    var error_msg;
    if(!q){
        error_msg = '搜索内容不能为空.';
    }
    if(error_msg){
        return res.status(422).send({error_msg:error_msg});
    }
    esearch.search(q).then(function (result) {
        return res.status(200).json({success: true,hits:result.hits.hits});
    }).catch(function (err) {
        return next(err);
    });
};